/* 
 * File:   main.cpp
 * Author: fozut
 *
 * Created on 15 de Dezembro de 2009, 11:24
 */
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;


#include <stdlib.h>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

#include "DTAHash.h"
#include "DTALinkedList.h"
#include "DTAList.h"
#include "DTAPonto.h"
#include "DTATriangulo.h"
#include "DTATriMesh.h"
#include "DTAReader.h"
#include "Hunter.h"

#include <stdio.h>


using namespace std;


/*
 * 
 */
int main(int argc, char** argv) {

  /*  DTAPonto p1,p2,p3;
    DTATriangulo tr;
    


   p1.x =0.0; p1.y= 0.0; p1.z = 0.0;
   p2.x =3.0; p2.y= 0.0; p2.z = 0.0;
   p3.x =1.5; p3.y= 3.5; p3.z = 0.0;

   tr.p1 = p1; tr.p2 = p2; tr.p3 = p3;
   tr.print();

   tr.p1 = p1; tr.p2 = p3; tr.p3 = p2;
   tr.print();

   tr.p1 = p2; tr.p2 = p1; tr.p3 = p3;
   tr.print();

   tr.p1 = p2; tr.p2 = p3; tr.p3 = p1;
   tr.print();

   tr.p1 = p3; tr.p2 = p2; tr.p3 = p1;
   tr.print();

   tr.p1 = p3; tr.p2 = p1; tr.p3 = p2;
   tr.print();
*/


   register int i,j;
   DTAPonto p1, p2, p3, p4;
   DTATriangulo tr;
   DTATriMesh *Mesh = new DTATriMesh;

   p1.x =0.0; p1.y= 0.0; p1.z = 0.0;
   p2.x =2.0; p2.y= 0.0; p2.z = 0.0;
   p3.x =1.0; p3.y= 2.0; p3.z = 0.0;
   p4.x =1.0; p4.y= 4.0; p4.z = 0.0;


   //cria a malha de baixo pra cima
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
            tr.p1.x =static_cast<double>(i); tr.p1.y= static_cast<double>(j); tr.p1.z = 0.0;
            tr.p2.x =static_cast<double>(i+1); tr.p2.y= static_cast<double>(j); tr.p2.z = 0.0;
            tr.p3.x =static_cast<double>(i); tr.p3.y= static_cast<double>(j+1); tr.p3.z = 0.0;
            Mesh->addCell(tr);
       }
   }

   //cria a malha de cima pra baixo
   for(i=5;i>0;i--)
   {
       for(j=5;j>0;j--)
       {
            tr.p1.x =static_cast<double>(i); tr.p1.y= static_cast<double>(j); tr.p1.z = 0.0;
            tr.p2.x =static_cast<double>(i-1); tr.p2.y= static_cast<double>(j); tr.p2.z = 0.0;
            tr.p3.x =static_cast<double>(i); tr.p3.y= static_cast<double>(j-1); tr.p3.z = 0.0;
            Mesh->addCell(tr);
       }
   }

   p1.x =1.0; p1.y= 1.0; p1.z = 0.0;
   p2.x =2.0; p2.y= 1.0; p2.z = 0.0;
   p3.x =1.0; p3.y= 2.0; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;

   p4.x= 2.0; p4.y = 2.0; p4.z = 0.0;
   p1.x =2.0; p1.y= 2.5; p1.z = 0.0;



   Mesh->alterPoint(p4,p1);


   p1.x =2.0; p1.y= 1.0; p1.z = 0.0;
   p2.x =2.0; p2.y= 2.5; p2.z = 0.0;
   p3.x =3.0; p3.y= 1.0; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;

   p1.x =2.0; p1.y= 1.0; p1.z = 0.0;
   p2.x =2.0; p2.y= 2.5; p2.z = 0.0;
   p3.x =1.0; p3.y= 2.0; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;

   p1.x =1.0; p1.y= 2.0; p1.z = 0.0;
   p2.x =2.0; p2.y= 2.5; p2.z = 0.0;
   p3.x =1.0; p3.y= 3.0; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;

   p1.x =1.0; p1.y= 2.0; p1.z = 0.0;
   p2.x =1.0; p2.y= 3.0; p2.z = 0.0;
   p3.x =2.0; p3.y= 2.5; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;

   p1.x =2.0; p1.y= 3.0; p1.z = 0.0;
   p2.x =3.0; p2.y= 2.0; p2.z = 0.0;
   p3.x =2.0; p3.y= 2.5; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;

   p1.x =3.0; p1.y= 1.0; p1.z = 0.0;
   p2.x =3.0; p2.y= 2.0; p2.z = 0.0;
   p3.x =2.0; p3.y= 2.5; p3.z = 0.0;
   tr.p1 = p1; tr.p2 =p2; tr.p3 = p3;
   cout <<Mesh->findTriangles(tr) << endl;











 /*
    register int i,j,k;
    //string nameFile = "../Models/Apple.txt";
    //string nameFile = "../Models/Sphere.txt";
    string nameFile = "Sphere.txt";
    DTAReader *DReader;
    DReader = new DTAReader(nameFile);
    //DTAReader DReader(nameFile);
   // DTAHash<DTAPonto>* DHashReader;
    DTATriMesh* MeshReader;
    
    MeshReader = DReader->readModel();
   // DHashReader = DReader.readPoints();
    cout << "Numero de pontos lidos em main " <<DReader->getNumberPoints() << endl;
    cout << " Numero de Triangulos lidos em main "<<DReader->getNumberTriangles() << endl;

    //MeshReader->removeCell(DReader->vectTr[0]);
    int cont =0;
    for(i=0;i<DReader->getNumberTriangles();i++)
    {
       // cout << "procurando triangulos" << endl;
        if( MeshReader->findTriangles(DReader->vectTr[cont]) ==  false)
        {
            cout << "procura por triangulo false em main" << endl;
        }
        else
           cout << MeshReader->getVizinhos(DReader->vectTr[cont])->getNumReg() << endl;
        cont++;
    }
*/























   /* srand((unsigned)time(0));
    DTAPonto pt;
    
    DTAHash<DTAPonto> DHash(7000);
    vector<DTAPonto> pts;
    int cont;
/*
    cout << "Procurando Pontos" << endl;
    for(i=0;i<DReader.getNumberPoints();i++)
    {
        if( DHashReader->finData(DReader.vectPt[i]) == false)
            cout << "ai deus" << endl;
    }
    cout << "Fim da procura dos pontos " << endl;
*/
   

    

    
/*

    //cout << str;
    

    DTATriMesh DMesh;

  //  pt.x =1.0; pt.y = 0.0; pt.z = 0.0;
   // pt1.x= 1.0; pt1.y = 1.0; pt1.z = 0.0;

    DTAPonto p1,p2,p3,p4,p5,p6;
    DTATriangulo tr,tr1;

    p1.x = 0.0; p1.y = 0.0; p1.z = 0.0;
    p2.x = 1.0; p2.y = 0.0; p2.z = 0.0;
    p3.x = 0.0; p3.y = 1.0; p3.z = 0.0;
    p4.x = -1.0; p4.y = 0.0; p4.z = 0.0;
    p5.x = 1.0; p5.y = 1.0; p5.z = 0.0;
    p6.x = 1.0; p6.y = -1.0; p6.z = 0.0;


    //tr.p1 = p1; tr.p2 = p2; tr.p3 = p3;
    //tr1.p1 = p3; tr1.p2 = p1; tr1.p3 = p4;

    //cout << (tr == tr1) <<endl;
    //cout << (tr!= tr1) << endl;
    

    const DTATriMesh::MeshCell *mmt;

    tr.p1 = p1; tr.p2 = p2; tr.p3 = p3;
    mmt = DMesh.addCell(tr);
    if (mmt == NULL)
        cout << "fudeo" << endl;

    tr.p1 = p1; tr.p2 = p4; tr.p3 = p3;
    mmt = DMesh.addCell(tr);
    if (mmt == NULL)
        cout << "fudeo" << endl;

    tr.p1 = p1; tr.p2 = p2; tr.p3 = p6;
    mmt = DMesh.addCell(tr);
    if (mmt == NULL)
        cout << "fudeo" << endl;

    tr.p1 = p2; tr.p2 = p3; tr.p3 = p5;
    mmt = DMesh.addCell(tr);
    if (mmt == NULL)
        cout << "fudeo" << endl;

    tr.p1 = p1; tr.p2 = p4; tr.p3 = p6;
    mmt = DMesh.addCell(tr);
    if (mmt == NULL)
        cout << "fudeo" << endl;



    DMesh.removeCell(tr);
   // DMesh.removeCell(tr);
    DMesh.addCell(tr);
    DMesh.addCell(tr);


   DTALinkedList<const DTAHash<DTAMeshTriangle>::HashNode*>* triangles = DMesh.getTriangles(p3);

   
   tr.p1 = p1; tr.p2 = p4; tr.p3 = p3;
   cout <<DMesh.findTriangles(tr) << endl;


   tr.p1 = p1; tr.p2 = p2; tr.p3 = p6;
   cout <<"procura do triangulo: " <<DMesh.findTriangles(tr) << endl;

   DTALinkedList<DTATriangulo> *vizRet = DMesh.getVizinhos(tr);

   
   DTAPonto pp;
   const DTATriangulo *tttr;

   for(i=0;i<vizRet->getNumReg();i++)
   {
        tttr =  vizRet->getData(i);
        pp = tttr->p1;
        pp.print();
        pp = tttr->p2;
        pp.print();
        pp = tttr->p3;
        pp.print();
        cout << endl;
   }

   
   






   cout << DMesh.findPoint(p1);
   cout << DMesh.findPoint(p2);
   cout << DMesh.findPoint(p3);
   cout << DMesh.findPoint(p4);



   vector<int> precision;
   precision.reserve(9000);

   for(i=0;i<7000;i++)
   {
       precision[i] = 0;
   }

   int mdd;
   vector<DTAPonto> vdPonto;
   for(i=0;i<93000;i++)
   {
       p1.x = rand()%1000*3.141516;
       p1.y = rand()%1000*3.141516;
       p1.z = rand()%1000*3.141516;
       //vdPonto.push_back(p1);
       //DHash.addData(p1);
       mdd = fmod(( 3*pow(p1.x,2.0) + 3*pow(p1.y,3.0) + 5*pow(p1.z,5.0)),1000);
       if(mdd<0) mdd = (-1)*mdd;
       precision[mdd]++;

   }

   DTALinkedList<int> Dlink;
   Dlink.addData(0);
   Dlink.addData(1);
   Dlink.addData(2);
  // Dlink.addData(3);

   cout << endl;
   const int *ret;
   ret = Dlink.getData(3);

   

   if(ret != NULL)
   cout << *ret;


*/







   
/*
   cont=0;
   for(i=0;i<93000;i++)
   {
       p1 = vdPonto[i];
       if( DHash.finData(p1) == false)
           cout << "bosta" << endl;

       cont++;
   }


   cout << endl;



   int max=0;
   for(i=0;i<1000;i++)
   {
       cout << precision[i] << " " ;
       if(precision[i] >max) max = precision[i];
   }
   cout << endl;

   cout << max;














   //triangles->printDataFolha();

/*
    cont=0;
    for(i=0;i<100;i++)
        for(j=0;j<10;j++)
            for(k=0;k<100;k++)
            {
                pt.x = (double) i;//rand()%10000;
                pt.y = (double) j;//rand()%10000;
                pt.z = (double) k;//rand()%10000;
                pt.id = cont;
                pts.push_back(pt);

                DHash.addData(pt);
                cont++;
            }
        
    cont =0;
    for(i=0;i<100;i++)
        for(j=0;j<10;j++)
            for(k=0;k<100;k++)
            {
                pt = pts[cont];

                if( DHash.finData(pt)== false)
                cout << "encontrou um false" << endl;

                cont++;
            }
*/
       

    return (EXIT_SUCCESS);
}

